package cn.zhiwen.demo;

class MyThread extends Thread {
    /**
     * 测试Thread.curentThread()和this
     */
    @Override
    public void run() {
        try {
            Thread.sleep(500);
            Thread t = Thread.currentThread();
            System.out.println("当前线程名字：" + t.getName() + " 当前线程的优先级别为：" + t.getPriority() + " ID:" + t.getId() + "存活状态:" + t.isAlive());
            System.out.println("当前线程名字：" + this.getName() + " 当前线程的优先级别为：" + this.getPriority() + " ID:" + this.getId() + "存活状态:" + this.isAlive());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

public class TestDemo {
    public static void main(String[] args) {
        MyThread mt = new MyThread();
        new Thread(mt, "Name1").start();
        new Thread(mt, "Name2").start();
        new Thread(mt).start();
        System.out.println(Thread.currentThread().getName()); // main主方法
    }
}
